<template>
	<view class="content u-rela">
		<u-image src='https://www.sqkjkj.vip/wxImg/common/bigturntable/banner.png' width='750rpx' height='1664rpx'></u-image>
		<view class="u-abso u-t-0">
			<view class="u-w-750 u-flex u-row-between u-p-20">
				<view class="cl_FFF">幸运大转盘</view>
				<view class="cl_FFF" @click="$u.route('/pages/home/Win')">中奖纪录</view>
			</view>
			<view class="u-w-710 u-p-l-60" style="padding-top: 100rpx;">
				<u-image src="https://www.sqkjkj.vip/wxImg/common/bigturntable/img7.png" mode="aspectFill" width="618rpx" height='122rpx'>
				</u-image>
			</view>
			<pt-lottery ref="pt-lottery" lotteryBg="https://www.sqkjkj.vip/wxImg/common/bigturntable/lotteryBg.png"
				lotteryBtn="https://www.sqkjkj.vip/wxImg/common/bigturntable/lotteryBtn.png" :times="how_num" :prizeList="prizeList" @start="start" @end="end">
			</pt-lottery>
			<!-- 兑换次数 -->
			<view class="u-w-530 u-auto u-rela ">
				<u-image src="https://www.sqkjkj.vip/wxImg/common/bigturntable/img8.png" mode="aspectFill" width="528rpx" height='96rpx'>
				</u-image>
				<view class="u-abso u-t-20 u-w-530 u-text-center cl_C92736FF u-weight"
					@click="$u.route('/pages/home/exchange?num='+how_num)">兑换次数</view>
			</view>

			<!-- 活动说明 -->
			<view class="u-w-660 u-auto u-m-t-30 u-p-20" style="background-color: #FFE4B7FF;">
				<view class=" u-flex u-row-center">
					<u-image src="https://www.sqkjkj.vip/wxImg/common/bigturntable/img6.png" mode="aspectFill" width="116rpx"
						height='18rpx'>
					</u-image>
					<view class="cl_C92736FF u-p-10 u-font-20 u-m-t-20 u-weight">活动说明</view>
					<u-image src="https://www.sqkjkj.vip/wxImg/common/bigturntable/img9.png" mode="aspectFill" width="116rpx"
						height='18rpx'>
					</u-image>
				</view>
				<u-parse :html="description_of_lottery"></u-parse>
			</view>
		</view>


		<!-- 中奖弹窗 -->
		<view class="div" v-if="show" @click="show=false">
			<!-- 没中奖 -->
			<view class=" warp u-t-0 u-l-0 " v-if='text=="谢谢惠顾"'>
				<view class="u-abso">
					<u-image src="https://www.sqkjkj.vip/wxImg/common/bigturntable/nos.png" mode="aspectFill" width="630rpx"
						height='730rpx'></u-image>
				</view>
				<view class="u-abso u-b-480 u-l-150">
					<u-image src="https://www.sqkjkj.vip/wxImg/common/bigturntable/img2.png" mode="aspectFill" width="450rpx"
						height='104rpx'></u-image>
				</view>
				<view class="bas u-abso u-b-460 u-w-406 u-h-134 u-l-h-134 u-text-center" style="color: #FFFEC6FF;"
					@click="true_agin">
					点击再来一次</view>
				<view class=" u-abso   u-text-center" style="color: #FF320FFF;top: 860rpx">很遗憾，本次未中奖</view>
			</view>

			<!-- 中奖弹窗 -->
			<view class="u-rela warp u-t-0 u-l-0 u-w-750" v-else>

				<u-image src="https://www.sqkjkj.vip/wxImg/common/bigturntable/get.png" mode="aspectFill" width="630rpx" height='730rpx'>
				</u-image>
				<view class="u-abso ">
					<view class="u-rela" style="margin-top: 400rpx;">
						<view class="  u-font-28 u-text-center" style="color: #FF320FFF;">恭喜您中奖！ 请尽快领取</view>
						<!-- <u-image :src="text.prizeIcon" mode="aspectFill" width="120rpx" height='120rpx'></u-image> -->
						<view class="u-text-center" style="color: #DD4E00FF;">{{text}}</view>
						<view class="u-rela" style="margin-top: 100rpx;">
							<view class="">
								<u-image src="https://www.sqkjkj.vip/wxImg/common/bigturntable/img2.png" mode="aspectFill" width="450rpx"
									height='104rpx'></u-image>
							</view>
							<view @click="goTo" class=" u-abso u-t-0 u-w-406 u-h-134 u-l-h-114 u-text-center"
								style="color: #FFFEC6FF;">立即领取</view>
						</view>
					</view>


				</view>
			</view>
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				prizeIndex: 0,
				show: false,
				text: '',
				nums: 0,
				prizeList: this.prizeList = [{
					id: 1,
					prizeName: 'iphone 18',
					// prizeIcon: 'https://www.sqkjkj.vip/wxImg/common/bigturntable/prizeIcon.png'
				}, {
					ia: 2,
					prizeName: 'iphone 11',
					// prizeIcon: 'https://www.sqkjkj.vip/wxImg/common/bigturntable/prizeIcon.png'
				}, {
					id: 3,
					prizeName: 'iphone 10',
					// prizeIcon: 'https://www.sqkjkj.vip/wxImg/common/bigturntable/prizeIcon.png'
				}, {
					id: 4,
					prizeName: 'iphone 9',
					// prizeIcon: 'https://www.sqkjkj.vip/wxImg/common/bigturntable/prizeIcon.png'
				}, {
					prizeName: 'iphone 8',
					// prizeIcon: 'https://www.sqkjkj.vip/wxImg/common/bigturntable/prizeIcon.png'
				}, {
					id: 5,
					prizeName: 'iphone 7',
					// prizeIcon: 'https://www.sqkjkj.vip/wxImg/common/bigturntable/prizeIcon.png'
				}, {
					id: 6,
					prizeName: 'iphone 6',
					// prizeIcon: 'https://www.sqkjkj.vip/wxImg/common/bigturntable/prizeIcon.png'
				}, {
					id: 8,
					prizeName: '谢谢惠顾',
					// prizeIcon: 'https://www.sqkjkj.vip/wxImg/common/bigturntable/no.png'
				}],
				how_num:0,
				userinfo: '',
				description_of_lottery:'',
				arrat: []
			}
		},
		onLoad() {
			
		},
		onShow() {
			this.massage()
		},
		methods: {
			massage() {
				this.$api.get_my_massage({}, res => {
					if (res.data.code == 1) {
						// this.how_num = res.data.data.data.luck_num
						this.$refs['pt-lottery'].residueDegree=res.data.data.data.luck_num
						uni.setStorageSync("userinfo", this.userinfo)
						this.good_list()
					}
				})
			},
			good_list(){
				this.$api.good_list({}, res => {
					// this.how_num = res.data.data.score_trade_luck_num
					this.arrat = res.data.data.prize_list
					this.description_of_lottery= res.data.data.description_of_lottery
				})
			},
			// 点击开始抽奖
			start() {
				// 调取奖品接口
				this.$api.good_list_good({}, res => {
					if (res.data.code == 1) {
						console.log(res);
						let arr = res.data.data.prize_info.id
						for (var i = 0; i < this.arrat.length; i++) {
							if (arr == this.arrat[i].id) {
								this.prizeIndex = i
								this.$refs['pt-lottery'].init(this.prizeIndex)
							}
						}


					} else {
						uni.showToast({
							icon: 'none',
							title: res.data.msg
						})
					}
				})
				// this.prizeIndex = Math.ceil(Math.random() * 7)
				// this.$refs['pt-lottery'].init(this.prizeIndex)
			},
			end() {
				this.show = true
				console.log(this.prizeIndex);
				this.text = this.arrat[this.prizeIndex].title
				// switch (this.prizeIndex) {
				// 	case 7:
				// 		this.show = true
				// 		// uni.showToast({
				// 		// 	icon: 'none',
				// 		// 	title: '未中奖，再接再厉!'
				// 		// })
				// 		break;
				// 	default:
				// 		this.show = true
				// 		this.text = this.arrat[this.prizeIndex]
				// 		console.log(this.text)
				// 		// uni.showToast({
				// 		// 	icon: 'none',
				// 		// 	title: '恭喜您获取' + this.prizeList[this.prizeIndex].prizeName
				// 		// })
				// 		break;
				// }

			},
			// 点击再来一次
			true_agin() {
				this.start()
				this.show = false
			},
			backs() {
				uni.navigateBack()
			},
			// 兑换次数
			cishu() {
				// this.nums=4
			},
			goTo() {
				uni.setStorageSync("win", this.text)
				uni.showToast({
					icon: 'none',
					title: '领取成功'
				})
				this.show = false
				// setTimeout(() => {
				// 	uni.navigateTo({
				// 		url: '/pages/home/changeslist'
				// 	})
				// }, 500)
			}
		}
	}
</script>

<style scoped lang="scss">
	// page {
	// 	background: url("https://www.sqkjkj.vip/wxImg/common/bigturntable/banner.png") no-repeat;
	// 	background-size: 100% 100vh;
	// }
	.div {
		z-index: 999;
		position: fixed;
		top: 0;
		left: 0;
		width: 100%;
		height: 100%;
		background-color: rgba(0, 0, 0, .5);
	}
</style>
